/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2018 All Rights Reserved.
 */
package com.sgzn.sgpay.service.converter;

import com.sgzn.sgpay.enums.SeqFlagEnum;
import com.sgzn.sgpay.model.request.SgsShopAddRequest;
import com.sgzn.sgpay.model.request.SgsShopUpdateRequest;
import com.sgzn.sgpay.persistence.domain.TShop;
import com.sgzn.sgpay.util.SeqUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author zhongzhongyong
 * @version Id: ShopReqConverter.java, v 0.1 2018/5/20 22:54 zhongzhongyong Exp $$
 */
public class ShopReqConverter {

    /**
     * 获取门店新增实体
     * @param request
     * @return
     */
    public static TShop getShopAddRequest(SgsShopAddRequest request,String mchId){
        TShop tShop = new TShop();
        tShop.setShopId(SeqUtil.getShortSeq(SeqFlagEnum.SHOP_ID.getCode()));
        tShop.setShopName(request.getShopName());
        tShop.setAddress(request.getAddress());
        tShop.setProvince(request.getProvince());
        tShop.setCity(request.getCity());
        tShop.setCounty(request.getCounty());
        tShop.setMerchantId(mchId);
        tShop.setIsDefaultAddress(request.getIsDefaultAddress());
        tShop.setCreatedAt(new Date());
        tShop.setUpdatedAt(new Date());
        return tShop;
    }

    /**
     * 获取门店更新请求
     * @param request
     * @return
     */
    public static TShop getShopUpdateRequest(SgsShopUpdateRequest request){
        TShop tShop = new TShop();
        if(StringUtils.isNotBlank(request.getShopName())){
            tShop.setShopName(request.getShopName());
        }
        if(StringUtils.isNotBlank(request.getAddress())) {
            tShop.setAddress(request.getAddress());
        }
        if(StringUtils.isNotBlank(request.getProvince())) {
            tShop.setProvince(request.getProvince());
        }
        if(StringUtils.isNotBlank(request.getCity())) {
            tShop.setCity(request.getCity());
        }
        if(StringUtils.isNotBlank(request.getCounty())) {
            tShop.setCounty(request.getCounty());
        }
        if(StringUtils.isNotBlank(request.getIsDefaultAddress())) {
            tShop.setIsDefaultAddress(request.getIsDefaultAddress());
        }
        tShop.setUpdatedAt(new Date());
        return tShop;
    }

}
